import java.sql.Array;
import java.util.Arrays;

public class MyStack {
    public int[] elem;
    public int usedSize;

    public MyStack(int[] elem) {
        this.elem = new int[10];
    }

    public void push(int data){
        if(ifFull()){
            grow();
        }
        elem[usedSize++]=data;
    }
    public boolean ifFull(){
        return elem.length==usedSize;
    }
    private void grow(){
        elem= Arrays.copyOf(elem,elem.length*2);

    }
    public int pop(){
        if(isEmpty()){
            throw new  EmptyException("栈为空");
        }else {
            int k=usedSize-1;
            usedSize--;
            return elem[k];
        }
    }
    private boolean isEmpty(){
        return usedSize==0;
    }
    public int peek(){
        if(isEmpty()){
            throw new  EmptyException("栈为空");
        }else {
            return elem[usedSize-1];
        }
    }
}
